// JavaScript Document

var FormTest = function(){
//提交第一步
	this.error1 = false;	
	this.error2 = false;	
	this.error3 = false;	
	this.error4 = false;	
	this.error5 = false;	
	this.error6 = false;	
	this.error7 = false;	

	$('zusername').onblur = function(){
		request = send_request();
		request.onreadystatechange = Fromcheck.processrequest;
		var username = this.value;
		var tipsob = $('usertips');
		tipsob.className='tips';
		Fromcheck.error1 = false;
		
		if(username==""){
			tipsob.innerHTML="请先输入用户名";
			return false;
		}else if(username.length < 6){
			tipsob.innerHTML="输入的用户名不能少于6字节";
			return false;
		}else{
			reobj = tipsob;
			tipsob.innerHTML="正在发送数据...";
			url = '/module/ajax/checkuser/index.php?username='+username;
			//确定发送请求方式，URL，及是否同步执行下段代码
			request.open("GET",url,true);
			request.send(null);
		}
	}
	$('zpassword').onblur=function(){
		var nodevalue = this.value;
		var tipsob = $('passwordtips');
		tipsob.className='tips';
		Fromcheck.error2 = false;
		if(nodevalue.length < 6){
			tipsob.innerHTML="密码长度在6-20之间";
		}else if(nodevalue.length > 20){
			tipsob.innerHTML="密码长度在6-20之间";
		}else{
			tipsob.innerHTML="正确";
			Fromcheck.error2 = true;
		}
		if($('repeat_one').value){
			if($('repeat_one').value != nodevalue){
				$('repeat_onetips').innerHTML="两次密码输入不一致";
				Fromcheck.error3 = false;
			}else{
				$('repeat_onetips').innerHTML="正确";
				Fromcheck.error3 = true;
			}
		}
	}
	$('repeat_one').onblur=function(){
		var password = $('zpassword').value;
		var nodevalue = this.value;
		var tipsob = $('repeat_onetips');
		tipsob.className='tips';
		Fromcheck.error3 = false;
		if(nodevalue != password){
			tipsob.innerHTML="两次密码输入不一致";
		}else{
			tipsob.innerHTML="正确";
			Fromcheck.error3 = true;
		}
	}
	$('zemail').onblur = function(){
		var re = new RegExp(RegExp_Email); 
		var nodevalue = this.value;
		var tipsob = $('zemailtips');
		tipsob.className='tips';
		Fromcheck.error4 = false;	
		if( nodevalue.length < 1 ){
			tipsob.innerHTML = "邮箱地址不能为空";
		}else{
			if(nodevalue.match(re) == null){
				tipsob.innerHTML = "邮箱格式不正确";
			}else{
				tipsob.innerHTML="正确";
				Fromcheck.error4 = true;	
			}
		}
	}
	$('imgcode').onblur = function(){
		var nodevalue = this.value;
		var tipsob = $('imgcodetips');
		tipsob.className='tips';
		Fromcheck.error5 = false;
		if(nodevalue.length < 4){
			tipsob.innerHTML = "验证码有误";
		}else{
			tipsob.className='';
			tipsob.innerHTML = "";
			Fromcheck.error5 = true;
		}
	}
	
//提交第二步
	this.error2_1 = false;	
	this.error2_2 = false;	
	this.error2_3 = false;
	this.error2_4 = false;	

	$('minid').onblur = function(){
		var nodevalue = this.value;
		var tipsob = $('zbelongtips');
		tipsob.className='tips';
		Fromcheck.error5 = false;
		if(nodevalue.length < 4){
			tipsob.innerHTML = "验证码有误";
		}else{
			tipsob.className='';
			tipsob.innerHTML = "";
			Fromcheck.error5 = true;
		}
	}
}
	//处理返回信息的函数
FormTest.prototype.processrequest = function(){
	var data='';
	if(request.readyState==4){//判断对象状态
		if(request.status==200){//信息已成功返回，开始处理信息
			var results = request.responseText;
			/*
			var results = request.responseXML;
			//var results = request.responseText;
			var xmldata = results.getElementsByTagName("data");
 			for (var i = 0; i< xmldata.length; i++){
				data =  xmldata[i];
				name = data.getElementsByTagName("mesg")[0].firstChild.nodeValue;
			}
			*/
			if(results == 1){
				reobj.innerHTML = '用户名已经存在';
			}else if(results == 2){
				reobj.innerHTML = '恭喜您可以注册这个用户';
				Fromcheck.error1 = true;
			}else if(results == 3){
				reobj.innerHTML = '用户名不能为空';
			}else{
				reobj.innerHTML = '用户名书写不正确';
			}
		}else{//页面不正常
			//alert("您所请求的页面不正常！");
		}
	}
}

FormTest.prototype.AllSubmit = function(){
	if(!this.error1){
		$('zusername').focus();
		return false;
	}
	if(!this.error2){
		$('zpassword').focus();
		return false;
	}
	if(!this.error3){
		$('repeat_one').focus();
		return false;
	}
	if(!this.error4){
		$('zemail').focus();
		return false;
	}
	if(!this.error5){
		$('imgcode').focus();
		return false;
	}
	var flag = this.error1 && this.error2 && this.error3 && this.error4 && this.error5;
	if(flag){
		$('submit').disabled = true;
	}
	return flag;
}

FormTest.prototype.Step2AllSubmit = function(){
	this.Ccompany('Ccompany','error1');
	this.checkAddress('Caddress','error2');
	this.checkCountry('Ccountry','Cprovince', 'input_province','error3');
	this.checkCity('Ccity','error5');
	this.checkTimeZone('Ftimezone','error6');
	this.checkTelephone('Telephone1','Telephone2','Telephone3','error7');
	this.checkParentid('parentid','error8');
	this.checkBusinessRange('Cbusinessrange','error9');
	this.checkEmployeesNumber('Cemployeesnumber','error10');
	this.checkIntroduction('Cintroduction','error11');
	this.checkKeywords('Ckeywords','error12');
	this.checkFullname('Cfullname','error13');
	this.SecurityEmail('Cemail','error14');
	return this.error6 && this.error2_1 && this.error2_2  && this.error2_4 && this.error2_5 && this.error2_6 && this.error2_7 && this.error2_8 && this.error2_9 && this.error2_10 && this.error2_11 && this.error2_12;
}

FormTest.prototype.SecurityEmail = function( id , errorid){
	res = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 
	var re = new RegExp(res); 
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);

	errorOb.style.display = "none";
	if(value.length < 1 ){
		errorOb.innerHTML = "Please enter an e-mail address.";
		errorOb.style.display = "block";
		this.error6 = false;
	}else{
		if(value.match(re) == null){
			errorOb.innerHTML = "Please enter an correct alternative e-mail address.";
			errorOb.style.display = "block";
			this.error6 = false;
		}else{
			this.error6 = true;	
		}
	}
}
FormTest.prototype.PhotoCode = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);

	errorOb.style.display = "none";
	if(value.length !== 4 ){
		errorOb.innerHTML = "Please type the verification code you see in the picture above.";
		errorOb.style.display = "block";
		this.error7 = false;
	}else{
		this.error7 = true;	
	}
}



FormTest.prototype.Ccompany = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 4){
		errorOb.innerHTML = "Please enter Company Name.";
		errorOb.style.display = "block";
		this.error2_1 = false;
	}else{
		this.error2_1 = true;	
	}
}
FormTest.prototype.checkAddress = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please enter Company Address";
		errorOb.style.display = "block";
		this.error2_2 = false;
	}else{
		this.error2_2 = true;	
	}
}
/*
FormTest.prototype.checkCountry = function( id1 , id2 , id3 , errorid){
	var value1 = document.getElementById(id1).value;
	var value2 = document.getElementById(id2).value;
	var value3 = document.getElementById(id3).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if( value2 == "" && value1 == "China"){
		errorOb.innerHTML = "Please select Province/State.";
		errorOb.style.display = "block";
		this.error2_3 = false;
	}else if( value3 == "" && value1 != "China"){
		errorOb.innerHTML = "Please select Province/State.";
		errorOb.style.display = "block";
		this.error2_3 = false;
	}else{
		this.error2_3 = true;
	}
}
*/
FormTest.prototype.checkCity = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please select City/Town";
		errorOb.style.display = "block";
		this.error2_4 = false;
	}else{
		this.error2_4 = true;	
	}
}
FormTest.prototype.checkTimeZone = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please select Timezone.";
		errorOb.style.display = "block";
		this.error2_5 = false;
	}else{
		this.error2_5 = true;	
	}
}
FormTest.prototype.checkTelephone = function( id1 , id2 , id3 , errorid){
	res = /^\d+$/; 
	var re = new RegExp(res); 
	var value1 = document.getElementById(id1).value;
	var value2 = document.getElementById(id2).value;
	var value3 = document.getElementById(id3).value;
	var errorOb = document.getElementById(errorid);
	errorOb.style.display = "none";
	if( ( value1.match(re) && value2.match(re) && value3.match(re) ) == null){
		errorOb.innerHTML = "Please enter correct Telephone number.";
		errorOb.style.display = "block";
		this.error2_6 = false;
	}else{
		this.error2_6 = true;	
	}
}
FormTest.prototype.checkParentid = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please select Company Category";
		errorOb.style.display = "block";
		this.error2_7 = false;
	}else{
		this.error2_7 = true;	
	}
}
FormTest.prototype.checkBusinessRange = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please enter Business Range.";
		errorOb.style.display = "block";
		this.error2_8 = false;
	}else{
		this.error2_8 = true;	
	}
}
FormTest.prototype.checkEmployeesNumber = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please select EmployeesNumber.";
		errorOb.style.display = "block";
		this.error2_9 = false;
	}else{
		this.error2_9 = true;	
	}
}
FormTest.prototype.checkIntroduction = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please enter Company Discription.";
		errorOb.style.display = "block";
		this.error2_10 = false;
	}else{
		this.error2_10 = true;	
	}
}
FormTest.prototype.checkKeywords = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please enter a Keyword.";
		errorOb.style.display = "block";
		this.error2_11 = false;
	}else{
		this.error2_11 = true;	
	}
}
FormTest.prototype.checkFullname = function( id , errorid){
	var value = document.getElementById(id).value;
	var errorOb = document.getElementById(errorid);
	
	errorOb.style.display = "none";
	if(value.length < 1){
		errorOb.innerHTML = "Please enter a correct Contact Person name.";
		errorOb.style.display = "block";
		this.error2_12 = false;
	}else{
		this.error2_12 = true;	
	}
}

window.onload=function(){
	Fromcheck = new FormTest();
} 















